home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #5 / Amiga Plus CD - 2000 - No. 5.iso / Tools / Dev / fpc / source / docs / objectex / ex34.pp < prev    next >
Encoding:
Text File  |  2000-01-01  |  681 b   |  35 lines

  1. Program ex34;
  2.  
  3. { Program to demonstrate the TCollection.AtInsert method }
  4.  
  5. Uses Objects,MyObject; { For TMyObject definition and registration }
  6.  
  7. Var C : PCollection;
  8.     M : PMyObject;
  9.     I : Longint;
  10.  
  11. Procedure PrintField (Dummy: Pointer;P : PMyObject);
  12.  
  13. begin
  14.   Writeln ('Field : ',P^.GetField);
  15. end;
  16.  
  17.  
  18. begin
  19.   Randomize;
  20.   C:=New(PCollection,Init(120,10));
  21.   Writeln ('Inserting 100 records at random places.');
  22.   For I:=1 to 100 do
  23.     begin
  24.     M:=New(PMyObject,Init);
  25.     M^.SetField(I-1);
  26.     If I=1 then
  27.       C^.Insert(M)
  28.     else
  29.       With C^ do 
  30.         AtInsert(Random(Count),M);
  31.     end;
  32.   Writeln ('Values : ');
  33.   C^.Foreach(@PrintField);   
  34.   Dispose(C,Done);
  35. end.